import java.util.ArrayList;
import java.util.List;

public class ListTest {
	public List<User> list = new ArrayList<User>();
	public class T extends Thread{
		private List<User> list;
		public T( List<User> list){
			this.list=list;
		}
		
		public void run(){
			test();
		}
		
		public void test(){
			User user4=new User(4);
			list.add(user4);
			System.out.println(list==ListTest.this.list);
			//重新new一个list，并不会影响ListTest.this.list，2者是不同的引用对象
			list = new  ArrayList<User>();
			System.out.println(list==ListTest.this.list);
		}
	}
	
	public void test1(){
		User user1=new User(1);
		User user2=new User(2);
		User user3=new User(3);
		list.add(user1);
		list.add(user2);
		list.add(user3);
	}
	
	class User{
		private int id;
		
		public User(){}
		public User(int id){
			this.id=id;
		}
	
		public int getId() {
			return id;
		}
	
		public void setId(int id) {
			this.id = id;
		}

		@Override
		public String toString() {
			return "User [id=" + id + "]";
		}
	}
	
	public static void main(String[] args) {
		ListTest test=new ListTest();
		
		List<User> users=new ArrayList<User>();
		User user =test.new User();
		user.setId(123);
		users.add(user);
		user.setId(234);
		System.out.println(users);
		user = test.new User(); 
		System.out.println(users);
		List<User> temp = new ArrayList<User>();
		temp = users;
		users.clear();
		System.out.println(temp.size());
		test.test1();
		
		test.new T(test.list).start();
		
	}
}
